<template>
  <div>
    <h1>新闻列表</h1>
    <p>标题：<input type="text" v-model="from.title"></p>
    <p>内容：<input type="text" v-model="from.content"></p>
    <p>
      <button @click="addnews">添加</button></p>
    <table border="1px" cellspacing="0">
      <tr>
        <td>标题</td>
        <td>内容</td>
      </tr>
      <tr v-for="i in arr">
        <td>{{i.title}}</td>
        <td>{{i.content}}</td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  name: "news",
  data() {
    return {
      from:{},
      arr:[],

    }
  },
  methods: {
    addnews(){
      this.axios.post('news/',this.from
      ).then(res=>{
        console.log(res)
        alert(res.data.msg)
        this.from={}
      })
    },
    get_new(){
      this.axios.get('news/').then(res=>{
        console.log(res)
        this.arr=res.data
      })
    },
  },
  mounted() {
    this.get_new()
  }
}
</script>

<style scoped>

</style>
